package com.crb.smartcarddemo.http;


import com.crb.smartcarddemo.http.RequestBean.ApplyReq;
import com.crb.smartcarddemo.http.RequestBean.ResultReq;
import com.crb.smartcarddemo.http.RequestBean.SynReq;
import com.crb.smartcarddemo.http.ResponseBean.ApplyResp;
import com.crb.smartcarddemo.http.ResponseBean.Response;
import com.crb.smartcarddemo.http.ResponseBean.ResultResp;
import com.tencent.mmkv.MMKV;

import retrofit2.Call;
import retrofit2.Callback;

public class HttpUtils {

    private static ApiBase apiBase;
    private static ApiService iService;

    private Call call;
    public static MMKV mmkv;

    public static HttpUtils httpUtils;

    public synchronized static HttpUtils getInstance() {
        if (apiBase == null) {
            apiBase = new ApiBase();
        }
        if (iService == null) {
//            iService = apiBase.getService("http://192.168.8.10:8877/iccehwkey/app/");
            iService = apiBase.getService("https://test.otasim.com/social/security/tsm/personalization/");
            iService = apiBase.getService("http://192.168.8.43:9001/social/security/tsm/personalization/");
        }
        mmkv = MMKV.defaultMMKV();
        if (httpUtils == null) {
            httpUtils = new HttpUtils();
            return httpUtils;
        } else {
            return httpUtils;
        }
    }


    /**
     * 6.1.应用个人化申请
     */
    public void apply(ApplyReq applyReq, Callback<ApplyResp> callback) {
        call = iService.apply(applyReq);
        call.enqueue(callback);
    }

    /**
     * 6.2.指令执行结果通知
     */
    public void result(ResultReq resultReq, Callback<ResultResp> callback) {
        call = iService.result(resultReq);
        call.enqueue(callback);
    }

    /**6.3.业务状态同步*/
    public void syn(SynReq synReq, Callback<Response> callback) {
        call = iService.syn(synReq);
        call.enqueue(callback);
    }
}
